 
pkgbase=boost
pkgname=('boost-libs' 'boost')
pkgver=1.66.0
_pkgver=1_66_0
pkgrel=1
pkgdesc="Free peer-reviewed portable C++ source libraries"
arch=('x86_64')
url="http://www.boost.org/"
license=('custom')
makedepends=('icu>=58.2' 'python2' 'python3' 'bzip2' 'zlib' 'openmpi') 
source=("https://downloads.sourceforge.net/boost/${pkgbase}_${_pkgver}.tar.bz2"
        "python.diff")
license=('custom')
sha256sums=('5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9'
            '3984cfb1922a909d65794f173068da59fb2a7c4efdaf42911c3add329a2b9789')

build() {
  export _stagedir="${srcdir}/stagedir"
  local JOBS="$(sed -e 's/.*\(-j *[0-9]\+\).*/\1/' <<< ${MAKEFLAGS})"

  cd "${srcdir}"/${pkgbase}_${_pkgver}
  
  # keep option to build for python3, this reverts change in 1.62
  # https://github.com/boostorg/build/commit/78ffbe094400d277627b2c19ceb182d637b8baca
  #patch -p1 -i ${srcdir}/python.diff
  
  ./bootstrap.sh --with-toolset=gcc --with-icu --with-python=/usr/bin/python3

  # tools
  install -d -m 755 "${_stagedir}"/bin
  install tools/build/src/engine/bin.linuxx86_64/b2 "${_stagedir}"/bin/b2

  # Also build with python3 support, leaving 2 as default
   #echo "using python : 3.6 : /usr/bin/python3 : /usr/include/python3.6m : /usr/lib ;" >> project-config.jam
   sed -i "s|using python : 3.6 : /usr ;|using python : 3.6 : /usr/bin/python3 : /usr/include/python3.6m : /usr/lib ;|g" project-config.jam 
   # Support for OpenMPI
   echo "using mpi ;" >> project-config.jam
  
  #quickbook support
  install -d -m 755 "${_stagedir}"/share/boostbook
  cp -a tools/boostbook/{xsl,dtd} "${_stagedir}"/share/boostbook/

  # ${_stagedir} for split package
  "${_stagedir}"/bin/b2 \
      variant=release \
      debug-symbols=off \
      threading=multi \
      runtime-link=shared \
      link=shared,static \
      toolset=gcc \
      python=3.6 \
      cflags="${CPPFLAGS} ${CFLAGS} -O3" linkflags="${LDFLAGS}" \
      --prefix="${_stagedir}" \
      --layout=system \
      ${JOBS} \
      install
}

package_boost() {
    pkgdesc="Free peer-reviewed portable C++ source libraries - Development"
    depends=("boost-libs=${pkgver}")
    optdepends=('python3: for python3 bindings')
                #'python2: for python2 bindings')

    install -d -m 755 "${pkgdir}"/usr
    cp -a "${_stagedir}"/{bin,include,share} "${pkgdir}"/usr
    
    install -d "${pkgdir}"/usr/lib
    cp -a "${_stagedir}"/lib/*.a "${pkgdir}"/usr/lib/

    # license
    install -D -m644 "${srcdir}/${pkgbase}_${_pkgver}/LICENSE_1_0.txt" \
        "${pkgdir}"/usr/share/licenses/boost/LICENSE_1_0.txt
        
    ln -s /usr/bin/b2 "$pkgdir"/usr/bin/bjam
}

package_boost-libs() {
    pkgdesc="Free peer-reviewed portable C++ source libraries - Runtime"
    depends=('gcc-libs' 'bzip2' 'zlib' 'icu')
    optdepends=('openmpi: for mpi support')
    options=('!staticlibs')

    install -d -m 755 "${pkgdir}"/usr
    cp -a "${_stagedir}"/lib "${pkgdir}"/usr
    # included in boost:
    rm "${pkgdir}"/usr/lib/*.a

    # license
    install -D -m644 "${srcdir}/${pkgbase}_${_pkgver}/LICENSE_1_0.txt" \
        "${pkgdir}"/usr/share/licenses/boost-libs/LICENSE_1_0.txt
}

